package com.acme.bankapp.domain.bank;

import com.acme.bankapp.domain.bank.exceptions.NotEnoughFundsException;
import com.acme.bankapp.domain.bank.exceptions.OverDraftLimitExceededException;

public class CheckingAccount extends AbstractAccount {
    private double overdraft;

    public CheckingAccount(final double amount, final double overdraft) {
        super(amount);
        if (overdraft < 0 ) {
            throw new IllegalArgumentException("Negative overdraft");
        }
        this.overdraft = overdraft;
    }

    public double getOverdraft() {
        return overdraft;
    }

    @Override
    public void deposit(double amount) {
        super.deposit(amount);
    }

    @Override
    public void withdraw(double amount) throws OverDraftLimitExceededException {
        try {
            super.withdraw(amount);
        } catch (NotEnoughFundsException e) {
            throw new OverDraftLimitExceededException(e);
        }
    }

    @Override
    public double maximumAmountToWithdraw() {
        return getBalance() + getOverdraft();
    }

    @Override
    public String toString() {
        return "CheckingAccount{" + super.toString() +
                ", overdraft=" + getOverdraft() +
                '}';
    }
}
